package CustomUI;



import com.ydev.lazywallet.R;
import com.ydev.lazywallet.gui.Home;
import com.ydev.lazywallet.gui.ViewCell;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class Input_Dialog extends Dialog {
	
	LinearLayout llValueInput;
	
	EditText et_Key;
	EditText et_Value;

	public Input_Dialog(Context context, int i) {
		super(context);
		if (context instanceof Activity) {
	        setOwnerActivity((Activity) context);
		}
	
		init(i);
	}

	public void init(int i){
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.input_dialog);
		this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
		
		if(i==0){
			llValueInput=(LinearLayout)this.findViewById(R.id.llValueInput);
			llValueInput.setVisibility(View.GONE);
		}
		
		et_Key=(EditText)findViewById(R.id.editText_Key);
		et_Value=(EditText)findViewById(R.id.editText_Value);
		
		Button btn;
		
		btn=(Button)this.findViewById(R.id.buttonOK);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				OKClicked(null);
			}
		});
		
		btn=(Button)this.findViewById(R.id.buttonCancel);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				CancelClicked(null);
			}
		});
	}
	
	public void OKClicked(View v){
		 Activity owner = getOwnerActivity();
	        if (owner != null) {
	        	if(owner.getClass().equals(Home.class))
	        		((Home)owner).addObject(et_Key.getText().toString());
	        	else
	        		((ViewCell)owner).addObject(et_Key.getText().toString(), et_Value.getText().toString());
	            this.hide();
	        }
	        
	}
	
	public void CancelClicked(View v){
		this.hide();
	}
	
}
